/***************************************************************************

Copyright (c) Microsoft Corporation. All rights reserved.
This code is licensed under the Visual Studio SDK license terms.
THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.

***************************************************************************/

using System.ComponentModel.Design;
using System.Reflection;
using Microsoft.SpecFlowTfsLinker_Extension;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VsSDK.UnitTestLibrary;

namespace SpecFlowTfsLinker.Extension_UnitTests.MenuItemTests
{
    [TestClass]
    public class AddSpecFlowTest
    {
        /// <summary>
        /// Verify that a new menu command object gets added to the OleMenuCommandService. 
        /// This action takes place In the Initialize method of the Package object
        /// </summary>
        [TestMethod]
        public void InitializeSpecFlowCommand()
        {
            // Create the package
            IVsPackage package = new SpecFlowTfsLinkerExtensionPackage();
            Assert.IsNotNull(package, "The object does not implement IVsPackage");

            // Create a basic service provider
            OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices();

            // Site the package
            Assert.AreEqual(0, package.SetSite(serviceProvider), "SetSite did not return S_OK");

            //Verify that the menu command can be found
            var menuCommandID = new CommandID(GuidList.guidSpecFlowTfsLinker_ExtensionCmdSet,
                                              (int) PkgCmdIDList.SpecFlowTfsLinker);
            MethodInfo info = typeof (Package).GetMethod("GetService", BindingFlags.Instance | BindingFlags.NonPublic);
            Assert.IsNotNull(info);
            var mcs = info.Invoke(package, new object[] {(typeof (IMenuCommandService))}) as OleMenuCommandService;
            Assert.IsNotNull(mcs.FindCommand(menuCommandID));
        }

        //[TestMethod]
        //public void SpecFlowItemCallback()
        //{
        //    // Create the package
        //    IVsPackage package = new SpecFlowTfsLinkerExtensionPackage();
        //    Assert.IsNotNull(package, "The object does not implement IVsPackage");

        //    // Create a basic service provider
        //    OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices();

        //    // Create a UIShell service mock and proffer the service so that it can called from the MenuItemCallback method
        //    BaseMock uishellMock = UIShellServiceMock.GetUiShellInstance();
        //    serviceProvider.AddService(typeof (SVsUIShell), uishellMock, true);

        //    // Site the package
        //    Assert.AreEqual(0, package.SetSite(serviceProvider), "SetSite did not return S_OK");

        //    //Invoke private method on package class and observe that the method does not throw
        //    MethodInfo info = package.GetType().GetMethod("ExecuteExtension",
        //                                                  BindingFlags.Instance | BindingFlags.NonPublic);
        //    Assert.IsNotNull(info, "Failed to get the private method ExecuteExtension throug reflection");
        //    info.Invoke(package, new object[] {null, null});

        //    //Clean up services
        //    serviceProvider.RemoveService(typeof (SVsUIShell));
        //}
    }
}